<?php
/*
 * LCMX 4.0 网站入口文件
 * ============================================================================
 * 版权所有: 山西龙采科技，并保留所有权利。
 * 网站地址: http://www.longcai0351.com
 * ============================================================================
 * @author LJay <ljay88@vip.qq.com>
 */
define('LC_MX',dirname(__FILE__).'/');//系统目录定义
header("Content-Type:text/html;charset=utf-8");
require_once 'x.php';
if(file_exists('config/config_db.php')){
	
	$page = isset($_GET['p'])?$_GET['p']:"index";//获取page参数
	$action = isset($_GET['a'])?$_GET['a']:null;//获取action参数
	
	include(LC_MX."config/config.php");//加载网站配置文件
	include(LC_MX."config/config_web.php");//加载全局配置文件
	if($have_phone){
		//检测移动设备访问（是否移动设备访问）
		$touch_arr =array("mobile","android","wap","uc","wml","vnd","adr","mqqbrowser","nokiaBrowser","playbook", "blackberry","bb10","ipad","iphone");
		$useragent=$_SERVER["HTTP_USER_AGENT"];//获取浏览器User-Agent (UA)
		$th=str_ireplace($touch_arr,'',$useragent);
		if($useragent<>$th){
			header("location:3g/");
			exit;
		}
	}
	if($action){
		//业务逻辑处理
		if(file_exists(LC_MX.'action/'.$action.'_action.php')){
			include(LC_MX.'common/core.php');//加载核心文件
			include(LC_MX.'action/'.$action.'_action.php');//加载对应操作文件
		}else{
			include 'resource/404/404.htm';
			exit;
		}
	}else{
		//view视图展示
		if($use_smarty){
			if(file_exists(LC_MX.'config/page_config.php')){
				$TPLPage = include(LC_MX."config/page_config.php");//加载page配置文件
			}
			$TPL = $TPLPage[$page]["tpl"];//获取指定模版文件名称
			if(!$TPL){
				include 'resource/404/404.htm';
				exit;
			}
			$TPL_URL = LC_MX."templates/{$TPL_folder}/".$TPL;//模版文件路径
			if(!file_exists($TPL_URL)){
				include 'resource/404/404.htm';
				exit;
			}
			include(LC_MX.'Lib/Smarty/tpl_show.php');//加载核心文件

            $sql="select * from ".lc()."_news where c_id=3 order by lc_id asc";
            $res_list=$db->getall($sql);

            $sql="select * from ".lc()."_news where c_id=4 order by lc_id asc limit 3";
            $advan_list=$db->getall($sql);

            $sql="select * from ".lc()."_products_type where c_pid=5 order by c_id desc";
            $type_list=$db->getall($sql);

            foreach($type_list as &$type){
                $sql=" SELECT mx_products_pics.lc_pic,mx_products.lc_id,mx_products.lc_title FROM ".lc()."_products_pics LEFT JOIN  mx_products on mx_products_pics .product_id=mx_products.lc_id where c_id= {$type['c_id']} GROUP BY mx_products_pics.product_id ";
                $sql .= " ORDER BY lc_id DESC LIMIT 8";
                $pro_list=$db->getall($sql);
                $type['pro_list']=$pro_list;
//var_dump($type['pro_list']);

            }
            unset($type) ;

            $sql="select * from ".lc()."_products_type where c_pid=6 order by c_id desc";
            $anli_type=$db->getall($sql);
            foreach($anli_type as &$anli){
                $sql=" SELECT mx_products_pics.lc_pic,mx_products.lc_id,mx_products.lc_title FROM ".lc()."_products_pics LEFT JOIN  mx_products on mx_products_pics .product_id=mx_products.lc_id where c_id= {$anli['c_id']} GROUP BY mx_products_pics.product_id ";
                $sql .= " ORDER BY lc_id DESC LIMIT 8";
                $anli_pro=$db->getall($sql);
                $anli['anli_pro']=$anli_pro;

            }
            unset($anli);
//var_dump($anli_type);
            $sql="select * from ".lc()."_danye where lc_id =1";
            $about=$db->getone($sql);

            $sql="select * from ".lc()."_news_type where c_id=5 ";
            $news_type=$db->getone($sql);


            $sql="select * from ".lc()."_news where c_id=5 order by lc_id desc limit 6";
            $news_list=$db->getall($sql);

            $sql="select * from ".lc()."_danye where lc_id =6";
            $contact=$db->getone($sql);

            $sql="select * from ".lc()."_banner where c_id =2 order by lc_id desc limit 1";
            $ad=$db->getone($sql);

            $sql="select * from ".lc()."_danye where lanmu=11 order by lc_id asc limit 1";
            $jiameng=$db->getone($sql);

            $smarty->assign("res_list",$res_list);
            $smarty->assign("advan_list",$advan_list);
            $smarty->assign("type_list",$type_list);
            $smarty->assign("anli_type",$anli_type);
            $smarty->assign("about",$about);
            $smarty->assign("news_list",$news_list);
            $smarty->assign("news_type",$news_type);
            $smarty->assign("contact",$contact);
            $smarty->assign("ad",$ad);
            $smarty->assign("jiameng",$jiameng);











            $smarty->assign("LCMX",$_CONFIG);//将标签配置赋值给smarty
			$smarty->display($TPL);
		}else{
			include(LC_MX.'common/functions.php');
			define("TPL_URL","templates/default_php/");//模版路径定义
			$view_page = LC_MX.TPL_URL.$page.".php";
			if(!file_exists($view_page)){
				include 'resource/404/404.htm';
				exit;
			}
			include($view_page);
		}
	}
}else{
	header("location:install/");
}
?>